<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!--
Not Automatically generated, changed!:
$Id: syntax_script_variables.htm,v 1.6 2011/12/04 15:27:59 wilbertd Exp $ 
-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Syntax - Script variables</title>
<link rel="stylesheet" type="text/css" href="../avisynth.css">
</head>
<body>
<h2><span class="mw-headline">AviSynth Syntax - Script variables</span></h2>
<p>This page shows how to use <i>variables</i> to store intermediate values for
further processing in a script. It also describes the types of data that scripts
can manipulate, and how <i>literals</i> (constants) of those types are written.</p>
<p>A <i>variable name</i> can be a character string of practically any length
(more than 4000 characters in Avisynth 2.56 and later) that contains (English)
letters, digits, and underscores (_), but no other characters. The name cannot
start with a digit.</p>
<p>You may use characters from your language system codepage (locale) in strings
and file names (ANSI 8 bit only, not Unicode).</p>
<p>A variable's placement in an <i>expression</i> is determined by the&nbsp;<a href="syntax_ref.htm" title="AviSynth Syntax">AviSynth
Syntax</a>.</p>
<p>Variables can have <span class="diffchange">a value of </span>one of the following <i>types</i>:</p>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">clip</span></li>
</ul>
<dl>
  <dd>A video clip containing video and / or audio. <span class="diffchange">A
    script must return a value </span>of <span class="diffchange">this </span>type.</dd>
</dl>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">string</span></li>
</ul>
<dl>
  <dd>A sequence of characters representing text. <span class="diffchange">String
    literals </span>are <span class="diffchange">written as text </span>surrounded
    either by &quot;quotation marks&quot; or by &quot;&quot;&quot;three
    quotes&quot;&quot;&quot;. <span class="diffchange">The </span>text can
    contain any <span class="diffchange">characters </span>except the
    terminating quotation mark or <span class="diffchange">triple</span>-<span class="diffchange">quote
    sequence</span>.</dd>
  <dd>The manual used to mention <i>TeX-style quotes</i>, but it has been
    confirmed that AviSynth doesn't work this way since v1.03. If you need to
    put a quotation mark inside a string, you need to use <a href="http://forum.doom9.org/showthread.php?s=&amp;threadid=71597" class="external text" title="http://forum.doom9.org/showthread.php?s=&amp;threadid=71597" rel="nofollow">Python-style</a>
    &quot;&quot;&quot;three quotes&quot;&quot;&quot;. For example:</dd>
</dl>
<pre>Subtitle(&quot;&quot;&quot;AVISynth is as they say &quot;l33t&quot;.&quot;&quot;&quot;) </pre>
<dl>
  <dd>Alternatively, you can use Windows extended-ASCII curly-quotes <span class="diffchange">inside
    the string</span> instead of
    straight quotes to get around this limitation.</dd>
</dl>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">int</span></li>
</ul>
<dl>
  <dd><span class="diffchange">An integer (32 bits, signed). An integer literal is </span>entered
    as a sequence of digits, optionally with a + or - at the beginning. <span class="diffchange">The
    value</span> can be given in <i>hexadecimal</i> by preceding them
    with a &quot;$&quot; character. For example <tt>$FF</tt> as well as <tt>$ff</tt>
    (case does not matter) are equal to 255.</dd>
</dl>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">float</span></li>
</ul>
<dl>
  <dd>A single-precision, <a href="http://en.wikipedia.org/wiki/Floating_point" class="external text" title="http://en.wikipedia.org/wiki/Floating_point" rel="nofollow">floating-point</a>
    number.
    Literals are entered as a sequence of digits with a decimal
    point (.) somewhere in it and an optional + or -. For example, +1. is
    treated as a floating-point number. Note that exponent-style notation is <b>not</b>
    supported.</dd>
</dl>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">bool</span></li>
</ul>
<dl>
  <dd>Boolean values must be either <i>true</i> or <i>false</i>. In addition
    they can be <span class="diffchange">written as </span>''yes'' or ''no'',
    but you should avoid <span class="diffchange">using these </span>in your
    scripts (they remain for compatibility purposes only).</dd>
</dl>
<ul>
  <li><span style="color: rgb(0, 0, 128); font-weight: bold;">val</span></li>
</ul>
<dl>
  <dd>A generic type <span class="diffchange">name</span>. It is applicable only inside a <a href="syntax_userdefined_scriptfunctions.htm" title="User defined script functions">user
    defined script function's</a> argument list, in order to be able to declare
    an argument variable to be of <i>any</i> type (int, float, bool, string, or
    clip). You must then explicitly test for its type (using the <a href="syntax_internal_functions_boolean.htm" title="Internal functions/Boolean functions">boolean
    functions</a>) and take appropriate actions.</dd>
</dl>
<p>There is another type which is used internally by Avisynth - the void or
'undefined' type. Its principal use is in conjunction with optional function
arguments. See the <a href="syntax_internal_functions_boolean.htm" title="Internal functions/Boolean functions">Defined()</a>
function.</p>
<p>Variables can be either <span style="color: rgb(0, 0, 128); font-weight: bold;">local</span>
 (<span class="diffchange">bound</span> to the local scope of the executing script block) or <span style="color: rgb(0, 0, 128); font-weight: bold;">global</span>.
Global variables are <span class="diffchange">bound</span> to the global script environment's scope and can be
accessed by all <a href="syntax_internal_functions.htm" title="Internal functions">Internal
functions</a>, <a href="syntax_userdefined_scriptfunctions.htm" title="User defined script functions">User
defined script functions</a>, <a href="syntax_runtime_environment.htm" title="Runtime environment">runtime
environment</a> scripts and the main script also.</p>
<p>To define and / or assign a value to a global variable you must precede its
name with the keyword <tt>global</tt> at the left side of the assignment. The
keyword is not needed (actually it is not allowed) in order to read the value of
a global variable. Examples:</p>
<pre>global canvas = <a href="corefilters/blankclip.htm" title="BlankClip">BlankClip</a>(length=200, pixel_type=&quot;yv12&quot;)
global stroke_intensity = 0.7
...
global canvas = <a href="corefilters/overlay.htm" title="Overlay">Overlay</a>(canvas, pen, opacity=stroke_intensity, mask=brush)</pre>
<p>To declare a variable, simply type the variable name, followed by '=' (an
equals sign), followed by its initial value. The type must not be declared; it
is inferred by the value assigned to it <span class="diffchange">(and can
actually be changed by subsequent assignments)</span>. The only place where it
is allowed (<span class="diffchange">though not strictly </span>required) to declare a variable's type is in <a href="syntax_userdefined_scriptfunctions.htm" title="User defined script functions">user
defined script function's</a> argument lists. Examples:</p>
<pre>b = false      # this declares a variable named 'b' of type 'bool' and initializes it to 'false'
x = $100       # type int (initial value is in hexadecimal)
y = 256        # type int (initial value is in decimal)
global f = 0.0 # type float declared globally
...
function my_recolor_filter(clip c, int new_color, float amount, val &quot;userdata&quot;) { ... }</pre>
<p><kbd>$Date: 2011/12/04 15:27:59 $</kbd></p>
</body>
</html>
